|
|
|
|
|
|
|
txtResultA text box used to hold the result of the calculation. |
|
|
|
|
|
|
|
|
cmdExecuteA command button used to perform the calculation. The users can change the button's caption through the ButtonCaption property of the control. |
|
|
|
|
|
|
|
|
After you finish placing the controls, your control should look similar to the one shown in Figure 15.4. |
|
|
|
|
|
|
|
|
The next step in creating the Calculator control is to write code for the properties. As you may recall from the preceding chapter, the ActiveX Control Interface Wizard enables you to expose properties, methods, and events of your control. The sample Calculator control includes a number of properties that can be exposed through the wizard. Follow these steps: |
|
|
|
|
|
|
|
|
See ''Using the ActiveX Control Interface Wizard," p. 323 |
|
|
|
|
|
|
|
|
1. Start the Wizard by choosing the ActiveX Control Interface Wizard item from the Add-Ins menu. Then click Next. |
|
|
|
|
|
|
|
|
2. In the Select Interface Members dialog box, add Caption property to the control. |
|
|
|
|
|
|
|
|
3. In the Create Custom Interface Members dialog box, add two new properties, a method, and an event, as shown in Figure 15.5. These custom members are as follows: |
|
|
|
 |
|
|
|
|
Operation propertyDetermines whether the control adds, subtracts, multiplies, or divides |
|
|
|
 |
|
|
|
|
ButtonCaption propertyDetermines the caption of the command button |
|
|
|
 |
|
|
|
|
ValidateEntries methodValidates user input into the text boxes |
|
|
|
 |
|
|
|
|
BadEntries eventFires when erroneous input is encountered |
|
|
|
|
|
|
|
|
Figure 15.5
The Calculator control needs four new control members. |
|
|
|
|
|
|
|
|
4. In the Set Mapping dialog box, map the ButtonCaption property to the Caption property of cmdExecute. Also, map the Caption property of the control to the Caption property of lblCaption. |
|
|
|
|
|